# coding: utf-8
'''
    斗地主发牌
    花色:♠ ♥ ♣ ♦
    数字:3 4 5 6 7 8 9 10 J Q K A 2
    大小王
'''
# 1.初始化一副牌
import random

color_list = ['♠', '♥', '♣', '♦']
num_list = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2']

poker_list = []

for i in num_list:
    for j in color_list:
        # 放入拍里面
        poker_list.append(j+i)
# 大小王
poker_list.append('小王')
poker_list.append('大王')
print(poker_list)
# 洗牌--->对应的下标
# 得到一个扑克牌的索引列表
poker_index_list = [i for i in range(len(poker_list))]
print(poker_index_list)

# 洗牌
random.shuffle(poker_index_list)
print(f'洗牌(索引)以后的牌:{poker_index_list}')

# 发牌:此处直接使用切片,如果想一个一个依次发牌可以使用for循环
# 1: 0369...48
# 2: 14710..49
# 3: 25811..50
# 随机一张地主索引,判断谁是地主
num = random.randint(0, 51)
# 判断地主
if 0 <= num < 17:
    print('一号玩家是地主')
elif 17 <= num < 34:
    print('二号玩家是地主')
else:
    print('三号玩家是地主')

player_index_1 = poker_index_list[0:17]
player_index_2 = poker_index_list[17:34]
player_index_3 = poker_index_list[34:51]
# 地主牌
landowner = poker_index_list[51:54]

# 先排序
player_index_1.sort()
player_index_2.sort()
player_index_3.sort()

# 根据索引拿到扑克牌
player_1 = [poker_list[i] for i in player_index_1]
player_2 = [poker_list[i] for i in player_index_2]
player_3 = [poker_list[i] for i in player_index_3]
land_d = [poker_list[i] for i in landowner]

print(f'玩家1的牌型:{player_1}')
print(f'玩家2的牌型:{player_2}')
print(f'玩家3的牌型:{player_3}')
print(f'地主牌:{land_d}')

